// pages/my/my.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
    wx.request({
      url: app.globalData.baseUrl + '/api/user/user_info',
      data: {
        session_key: app.gs()
      },
      success: res => {
        // console.log(res)
        that.setData({
          info: res.data.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  discountCoupon(e){
    wx.navigateTo({
      url: 'discountCoupon/discountCoupon',
    })
  },
  memberCard(e){
    wx.navigateTo({
      url: 'card/card',
    })
  },
  verificationCode(){
    wx.navigateTo({
      url: 'verificationCode/verificationCode',
    })
  },
  historyRecord(){
    wx.navigateTo({
      url: 'historyRecord/historyRecord',
    })
  },
  order(){
    wx.navigateTo({
      url: 'order/order',
    })
  },
  stockRecord(e){
    wx.navigateTo({
      url: 'stockRecord/stockRecord',
    })
  },
  bindPhone(e){
    wx.navigateTo({
      url: 'bindPhone/bindPhone',
    })
  },
  bindAddWine(e){
    console.log(e);
    wx.navigateTo({
      url: 'addWine/addWine',
    })
  }
})